﻿#region Copyright
// Copyright (c) 2011-2012 RaisingForce Team (Alikin Sergey)
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System.Diagnostics.Contracts;

namespace RaisingForce.Raise.Language.RStates
{
    sealed public class ObjectPosition :
        RState
    {
        #region Constructors

        private ObjectPosition()
            : base()
        { }

        #endregion

        #region Private Declarations

        private static readonly ObjectPosition noneState = new ObjectPosition();

        private static readonly ObjectPosition forwardState = new ObjectPosition();

        private static readonly ObjectPosition forwardLeftState = new ObjectPosition();

        private static readonly ObjectPosition forwardRightState = new ObjectPosition();

        private static readonly ObjectPosition leftState = new ObjectPosition();

        private static readonly ObjectPosition rightState = new ObjectPosition();

        private static readonly ObjectPosition backwardLeftState = new ObjectPosition();

        private static readonly ObjectPosition backwardRightState = new ObjectPosition();

        private static readonly ObjectPosition backwardState = new ObjectPosition();

        #endregion

        #region Properties

        public bool IsNone
        {
            get
            {
                return object.ReferenceEquals(this, ObjectPosition.noneState);
            }
        }

        public bool IsForward
        {
            get
            {
                return object.ReferenceEquals(this, ObjectPosition.forwardState)
                    || object.ReferenceEquals(this, ObjectPosition.forwardLeftState)
                    || object.ReferenceEquals(this, ObjectPosition.forwardRightState);
            }
        }

        public bool IsBackward
        {
            get
            {
                return object.ReferenceEquals(this, ObjectPosition.backwardState)
                    || object.ReferenceEquals(this, ObjectPosition.backwardLeftState)
                    || object.ReferenceEquals(this, ObjectPosition.backwardRightState);
            }
        }

        public bool IsLeft
        {
            get
            {
                return object.ReferenceEquals(this, ObjectPosition.leftState)
                    || object.ReferenceEquals(this, ObjectPosition.forwardLeftState)
                    || object.ReferenceEquals(this, ObjectPosition.backwardLeftState);
            }
        }

        public bool IsRight
        {
            get
            {
                return object.ReferenceEquals(this, ObjectPosition.rightState)
                    || object.ReferenceEquals(this, ObjectPosition.forwardRightState)
                    || object.ReferenceEquals(this, ObjectPosition.backwardRightState);
            }
        }

        #endregion

        #region Base Overrides

        protected override bool isDefault
        {
            get
            {
                return object.ReferenceEquals(this, ObjectPosition.Default);
            }
        }

        #endregion

        #region Public Static Properties

        public static ObjectPosition None
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.noneState;
            }
        }

        public static ObjectPosition Forward
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.forwardState;
            }
        }

        public static ObjectPosition ForwardLeft
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.forwardLeftState;
            }
        }

        public static ObjectPosition ForwardRight
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.forwardRightState;
            }
        }

        public static ObjectPosition Left
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.leftState;
            }
        }

        public static ObjectPosition Right
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.rightState;
            }
        }

        public static ObjectPosition BackwardLeft
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.backwardLeftState;
            }
        }

        public static ObjectPosition BackwardRight
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.backwardRightState;
            }
        }

        public static ObjectPosition Backward
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.backwardState;
            }
        }

        public static ObjectPosition Default
        {
            get
            {
                Contract.Ensures(Contract.Result<ObjectPosition>() != null);
                return ObjectPosition.noneState;
            }
        }

        #endregion
    }
}
